﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using FXnaAppBase;

using ASCore;

using ASAermod;



namespace ASApplication
{

    /// <summary>
    /// 计算模型aermet主类
    /// </summary>
    public class AermetRC : RunCommand
    {

        public AermetRC(string exeName, string exeArgs, string workPath,bool isStage2)
            : base(exeName, exeArgs, workPath)

        {


            this._isStage2 = isStage2;

 
        }




        bool _isStage2 = true;

        /// <summary>
        /// 这里是要区分第二步，与第三步
        /// </summary>
        public bool IsStage2
        {
            get { return _isStage2; }
            set { _isStage2 = value; }
        }

       


        public override void BeforeRun()
        {
            base.BeforeRun();

            //查看工作目录中，是否存在对应的exe文件

            string destPath = this.WorkPath + "aermet.exe";


            if (!System.IO.File.Exists(destPath))
            {

                //取得程序中的文件
                string m2005Path = ProjectService.CurrentService.GetAppPath(AppPath.EXES) + @"aermet.exe";

                if (System.IO.File.Exists(m2005Path))
                {
                    System.IO.File.Copy(m2005Path, destPath);

                }
                else
                {
                    System.Windows.MessageBox.Show("未找到可运行的文件 aermet.exe");
                }





            }

            




            //然后是准备写文件输入部分


           AermetData data=  ProjectService.CurrentService.Project.ASData.GetAermet();


           if (this._isStage2)
           {

               //第一次执行前，似乎还得写气象数据呢，

               //ProjectService.CurrentService.Project.ASData.SurfFile.WriteFile(this.WorkPath+ASCoreNames.SurfData);

               //ProjectService.CurrentService.Project.ASData.UpperAirFile.WriteFile(this.WorkPath + ASCoreNames.UpperAirData);



               data.WriteStage2File(this.WorkPath);

           }
           else
           {

               data.WriteStage3File(this.WorkPath);

 
           }










        }


    }
}
